package com.shenmazong.demo1907amongo.controller;

import com.shenmazong.demo1907amongo.utils.ResultResponse;
import com.shenmazong.demo1907amongo.vo.LoginVo;
import org.springframework.web.bind.annotation.*;

/**
 * @author 军哥
 * @version 1.0
 * @description: TODO
 * @date 2021/12/11 10:23
 */

@RestController
@RequestMapping(value = "/param")
public class ParamController {

    /**
     * @description 该种传参方式表示从formdata中获取参数
     * @author 军哥
     * @date 2021/12/11 10:35
     * @version 1.0
     */
    @GetMapping(value = "/first")
    public ResultResponse first(@RequestParam(name="name1",required = false) String name, @RequestParam("id") Integer id) {
        String data = id + "," + name;

        return ResultResponse.SUCCESS(data);
    }

    /**
     * @description 该种传参方式表示从url上获取参数
     * 注意：顺序不能变，参数不能省
     * @author 军哥
     * @date 2021/12/11 10:36
     * @version 1.0
     */
    @GetMapping(value = "/second/{name}/{id}")
    public ResultResponse second(@PathVariable("id") Integer id, @PathVariable("name") String name) {
        String data = id + "," + name;

        return ResultResponse.SUCCESS(data);
    }

    /**
     * @description 该种传参方式表示从[请求体]上获取参数
     * 规范：3个或3个以内的参数，用@RequestParam，3个以上用@RequestBody
     * @author 军哥
     * @date 2021/12/11 10:47
     * @version 1.0
     */
    @PostMapping(value = "/three")
    public ResultResponse three(@RequestBody LoginVo loginVo) {

        return ResultResponse.SUCCESS(loginVo);
    }
}
